--[[ kurinaxx.lua
********************************
*                                                            *
* The LUA++ Scripting Project        *
*                                                            *
********************************

This software is provided as free and open source by the
staff of The LUA++ Scripting Project, in accordance with 
the AGPL license. This means we provide the software we have 
created freely and it has been thoroughly tested to work for 
the developers, but NO GUARANTEE is made it will work for you 
as well. Please give credit where credit is due, if modifying,
redistributing and/or using this software. Thank you.

~~End of License Agreement
-- LUA++ staff, March 26, 2008. ]]

--[[Developers notes on this one :P
Actually SandTrap is bugged. It doesn't do any damage and stay tooooooo long. For about 2 minutes. Original one stays 2 seconds. 
Oh, and it doesnt appear near the target but near the caster xX  (and yes, I tested all SandTrap spells) But I will include it anyways, just commented out. 
Feel free to test it and tell me your ideas. I could spawn a dummy near the player that casts it and despawns? That'd actually be an idea!]]

cleave = 0

function KuriOnCombat(Unit, event)
	print "Kurinaxx combat started!"
	--Unit:RegisterEvent("KuriSandTrap", 8000, 0)
	Unit:RegisterEvent("KuriCleave", 3500, 0)
end

function KuriCleave(Unit, event)
	if cleave == 3 then
	Unit:ClearThreatList()
	print "Threatlist cleared"
	else
	end
	--Mortal wound... 28467 should be the right one. Its not a real cleave but this one deals damage and afflicts the "Mortal Wound" debuff to the target
	Unit:FullCastSpellOnTarget(28467, Unit:GetClosestPlayer())
	cleave = cleave+1
end

function KuriSandTrap(Unit, event)
	local player = Unit:GetRandomPlayer(0)
	if(player ~= nil) then
	local Xpos = player:GetX()
	local Ypos = player:GetY()
	local Zpos = player:GetZ()
	Unit:SpawnCreature(90007, Xpos, Ypos, Zpos, 0, 168, 10000)
	else
	end
end

function DummySandTrap(Unit, event)
	Unit:CastSpell(25648)
	sleep(2000)
	FullCastSpellOnTarget(25656, Unit:GetClosestPlayer())
	Unit:Despawn(100, 0)
	Unit:RegisterEvent("DummyTimerCheck", 1, 1)
end
--[[
function DummyTimerCheck(Unit, event)
	time = Timer:time()
	if(time > 1999) then
	print "TimeCheckSuccessful"
	--distance = Unit:GetDistance(target)
	--if(distance < 15) then
	print "DistanceCheckSuccessful"
	FullCastSpellOnTarget(25656, Unit:GetClosestPlayer())
	--end
	end
	Unit:Despawn(100, 0)
end
]]
function KuriOnLeaveCombat(Unit)
	print "Kurinaxx Wipe"
	Unit:RemoveEvents()
end

function KuriOnDied(Unit)
	print "Kurinaxx killed"
	Unit:RemoveEvents()
end

RegisterUnitEvent(90007, 18, "DummySandTrap")
RegisterUnitEvent(15348, 1, "KuriOnCombat")
RegisterUnitEvent(15348, 3, "KuriOnLeaveCombat")
RegisterUnitEvent(15348, 4, "KuriOnDied")